<?php

class m120527_193756_user extends CDbMigration
{
	public function up()
	{
	    $this->execute("CREATE TABLE `Profile` (
  `user_id` int(11) NOT NULL,
  `lastname` varchar(50) NOT NULL DEFAULT '',
  `firstname` varchar(50) NOT NULL DEFAULT '',
  `phone` varchar(255) NOT NULL DEFAULT '',
  `userType` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    
	    $this->execute("INSERT INTO `Profile` VALUES 
(1,'Admin','Administrator','',0),
(2,'Demo','Demo','',0),
(3,'Krzysztif','Borowiak','456456',0),
(4,'aaa','aaa','55555',0),
(5,'House','Gregory','666',2),
(6,'Burton','Clara','555',1);");
	    
	    $this->execute("
	            CREATE TABLE `ProfileField` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `varname` varchar(50) NOT NULL,
  `title` varchar(255) NOT NULL,
  `field_type` varchar(50) NOT NULL,
  `field_size` int(3) NOT NULL DEFAULT '0',
  `field_size_min` int(3) NOT NULL DEFAULT '0',
  `required` int(1) NOT NULL DEFAULT '0',
  `match` varchar(255) NOT NULL DEFAULT '',
  `range` varchar(255) NOT NULL DEFAULT '',
  `error_message` varchar(255) NOT NULL DEFAULT '',
  `other_validator` varchar(5000) NOT NULL DEFAULT '',
  `default` varchar(255) NOT NULL DEFAULT '',
  `widget` varchar(255) NOT NULL DEFAULT '',
  `widgetparams` varchar(5000) NOT NULL DEFAULT '',
  `position` int(3) NOT NULL DEFAULT '0',
  `visible` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `varname` (`varname`,`widget`,`visible`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;"
        );
	    
	    $this->execute("
	            INSERT INTO `ProfileField` VALUES 
(1,'lastname','Last Name','VARCHAR',50,3,1,'','','Incorrect Last Name (length between 3 and 50 characters).','','','','',2,3),
(2,'firstname','First Name','VARCHAR',50,3,1,'','','Incorrect First Name (length between 3 and 50 characters).','','','','',1,3),
(4,'phone','Phone','VARCHAR',255,0,1,'','','Phone number is not valid','','','','',0,1),
(7,'userType','User Type','INTEGER',1,0,2,'','0==Patient;1==Nurse;2==Doctor','User type required','','0','','',0,3);
	            ");
	
	    $this->execute("CREATE TABLE `User` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `username` varchar(20) NOT NULL,
          `password` varchar(128) NOT NULL,
          `email` varchar(128) NOT NULL,
          `activkey` varchar(128) NOT NULL DEFAULT '',
          `createtime` int(10) NOT NULL DEFAULT '0',
          `lastvisit` int(10) NOT NULL DEFAULT '0',
          `superuser` int(1) NOT NULL DEFAULT '0',
          `status` int(1) NOT NULL DEFAULT '0',
          PRIMARY KEY (`id`),
          UNIQUE KEY `username` (`username`),
          UNIQUE KEY `email` (`email`),
          KEY `status` (`status`),
          KEY `superuser` (`superuser`)
        ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;"
        );
	    
	    $this->execute("INSERT INTO `User` VALUES 
            (1,'admin','21232f297a57a5a743894a0e4a801fc3','webmaster@example.com','9a24eff8c15a6a141ece27eb6947da0f',1261146094,1338143390,1,1),
            (2,'demo','fe01ce2a7fbac8fafaed7c982a04e229','demo@example.com','099f825543f7850cc038b90aaff39fac',1261146096,0,0,1),
        ;");
	}

	public function down()
	{
		$this->dropTable("ProfileField");
		$this->dropTable("Profile");
		$this->dropTable("User");
	}
}